@extends('cms/system/admin/template/theme_default/common')
@section('page-body')
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-sm12">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <div class="layui-breadcrumb">
                            <a href="">首页</a>
                            <a href="">{{$data['app']['name']}}</a>
                            <a><cite>{{$data['name']}}</cite></a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm12">
                <div class="layui-card">
                    <div class="layui-card-header">回款记录</div>
                    <div class="layui-card-body">
                        <table id="office-receipt-list" lay-filter="office-receipt-list"></table>
                        <script type="text/html" id="toolbar-office-receipt-list">
                            <div class="layui-btn-container">
                                <button class="layui-btn layui-btn-sm" lay-event="receiptCreateFunc">添加</button>
                            </div>
                        </script>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm12">
                <div class="layui-card">
                    <div class="layui-card-header">支出记录</div>
                    <div class="layui-card-body">

                    </div>
                </div>
            </div>
            <div class="layui-col-sm12">
                <div class="layui-card">
                    <div class="layui-card-header">提成明细</div>
                    <div class="layui-card-body">

                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        layui.config({
            base: '/layui-admin/'
        }).extend({
            index: 'lib/index'
        }).use(['index', 'system'], function () {
            // 定义操作列表
            var actionList = {
                // 创建回款记录
                receiptCreateFunc: function () {
                    layui.system.iframeLayer({
                        sourceWindow: window,
                        targetName: 'top',
                        title: '添加',
                        content: layui.setter.mvcLink + '/office/admin_project/create?app_id={{$app['id'] ?? 0}}',
                        btn: ['确定', '取消'],
                        yes: function (layerIndex, layerWindow) {
                            // 点击确认触发 iframe 内容中的按钮提交
                            var submit = layerWindow.find('iframe').contents().find('#submit-create');
                            submit.click();
                        }
                    });
                },
                // 更新
                updateFunc: function (object) {
                    layui.system.iframeLayer({
                        sourceWindow: window,
                        targetName: 'top',
                        title: '添加',
                        content: layui.setter.mvcLink + '/office/admin_object/update?id=' + object.data.id,
                        btn: ['确定', '取消'],
                        yes: function (layerIndex, layerWindow) {
                            // 点击确认触发 iframe 内容中的按钮提交
                            var submit = layerWindow.find('iframe').contents().find('#submit-update');
                            submit.click();
                        }
                    });
                },
                // 详情
                detailFunc: function (object) {
                    var link = layui.setter.mvcLink + '/office/admin_project/detail?id=' + object.data.id;
                    if (IN_IFRAME) {
                        top.layui.index.openTabsPage(link, '项目详情');
                        return null;
                    }
                    window.location.href = link;
                    return null;
                },
                // 删除
                deleteFunc: function (data) {
                },
                // 支出明细
                disburseRetrieveFunc: function (object) {
                    var link = layui.setter.mvcLink + '/office/admin_disburse/retrieve?app_id=' + object.data.id;
                    if (IN_IFRAME) {
                        top.layui.index.openTabsPage(link, '支出管理');
                        return null;
                    }
                    window.location.href = link;
                    return null;
                },
                // 更多方法
                moreFunc: function (object) {
                    layui.dropdown.render({
                        elem: this,
                        show: true,
                        align: 'right',
                        data: [{
                            id: 'office-project-update',
                            title: '编辑',
                            action: 'updateFunc'
                        }, {
                            id: 'office-disburse-retrieve',
                            title: '支出明细',
                            action: 'disburseRetrieveFunc'
                        }, {
                            id: 'office-project-delete',
                            title: '删除',
                            action: 'deleteFunc'
                        }],
                        click: function (dropdownData, dropdownElement) {
                            return actionList[dropdownData.action] ? actionList[dropdownData.action].call(this, object) : '';
                        }
                    });
                },
            };
            // 回款记录
            layui.table.render({
                elem: '#office-receipt-list',
                toolbar: '#toolbar-office-receipt-list',
                url: layui.setter.apiLink + '/office/admin_receipt/retrieve?project_id={{$data['id'] ?? 0}}',
                parseData: function (result) {
                    return {
                        code: result.code == 1 ? 0 : 1,
                        msg: result.msg,
                        count: result.data.total,
                        data: result.data.items
                    }
                },
                cols: [[
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'id', width: 80, title: 'ID', sort: true},
                    {field: 'name', title: '回款日期'},
                    {field: 'amount', title: '回款金额'}
                ]],
                page: true,
                limit: 10,
                limits: [10, 15, 20, 25, 30],
                text: '数据加载异常！'
            });
        });
    </script>
@endsection